package com.nflakes.petrol.controllers;

import com.nflakes.petrol.model.PetrolStations;
import com.nflakes.petrol.services.GroovySlurperService;
import com.nflakes.petrol.services.SlurperService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

@Controller
public class PetrolController extends AbstractPetrolController {

    private final SlurperService slurperService = new GroovySlurperService();
    @RequestMapping("/petrol")
    public ModelAndView petrol() throws IOException, InstantiationException, IllegalAccessException {

        PetrolStations petrolStations = slurperService.slurpPetrolStations();

        return new ModelAndView("petrolXmlView", BindingResult.MODEL_KEY_PREFIX, petrolStations);
    }


}
